home *** CD-ROM | disk | FTP | other *** search
/ stazsoftware.com / www.stazsoftware.com.tar / www.stazsoftware.com / futurebasic / sample-code / UpdateButton.sit / FN SetButtonValue next >
Text File  |  2003-11-18  |  2KB  |  62 lines

  1.  
  2. /*
  3.      this function performs two important tasks
  4.      
  5.      task #1: it will not reset a button if it is already set
  6.               to the desired value.
  7.  
  8.      task #2: it resets the clip region of a window so that
  9.               the change in the button is immediately apparent.
  10.               i know that i have reset embedded appearance buttons
  11.               about a zillion times and wondered why my code didn't work
  12.               only to discover that the code was fine, but the 
  13.               update was clipped out of the window.
  14.  
  15.      task #3: [who said i could count] it ensures that the new value
  16.               is within the min/max parameters of the control. in the
  17.               olden days [circa system 9] this was not a requirement.
  18.               with the appearance manager, many controls can be set
  19.               outside of their own min/max ranges.
  20.  
  21.      task #4: after determining the proper value for the button and
  22.               setting it, it returns the new value to you as a result
  23.               of the function. if you try to set the control to an
  24.               improper value, you will learn (by looking at the fn
  25.               result) what the control was really set to. [did i just
  26.               end a sentence with a preposition?]
  27.  
  28.      to use this, instead of calling...
  29.  
  30.           button bRef , newValue
  31.  
  32.      call the function with...
  33.  
  34.           fn setButtonValue ( bRef , newValue )
  35.  
  36.      now that i have begun to use this function, my hair is 
  37.      starting to grow back.
  38.  
  39. */
  40.  
  41. local fn setButtonValue ( bRef as long , value as long)
  42. '~'9
  43. dim min as long
  44. dim max as long
  45. dim cH as handle
  46. dim rgn as rgnHandle
  47.  
  48. cH = button&(bRef)
  49. long if ch
  50. max = fn GetControlMaximum(cH)
  51. min = fn GetControlMinimum(cH)
  52. if value > max then value = max
  53. if value < min then value = min
  54. rgn = fn NewRgn
  55. GetClip(rgn)
  56. ClipRect(gBigRect)
  57. SetControlValue(cH , value)
  58. SetClip(rgn)
  59. end if
  60.  
  61. end fn = value
  62.